$(function () {
    /**
     * 生成导航
     */
    $(document).ready(function (e) {
        $(".xj-docs-next-menu").append("<a style='font-size: 16px' href='#title'>" + $("#docInfoName").html() + "</a><br/>");
        $(".github-markdown-body").children().each(function (index, element) {
            var tagName = $(this).get(0).tagName;
            if (tagName.substr(0, 1).toUpperCase() == "H") {
                var contentH = $(this).html();//获取内容
                var markid = "mark-" + tagName + "-" + index.toString();
                $(this).attr("id", markid);//为当前h标签设置id
                let spaceNum = "";
                if (tagName === 'H1') {
                    spaceNum = "";
                } else if (tagName === 'H2') {
                    spaceNum = "";
                } else if (tagName === 'H3') {
                    spaceNum = "1.5";
                } else if (tagName === 'H4') {
                    spaceNum = "3";
                } else if (tagName === 'H5') {
                    spaceNum = "4.5";
                } else if (tagName === 'H6') {
                    spaceNum = "6";
                }
                spaceNum += "em";
                $(".xj-docs-next-menu").append("<a href='#" + markid + "' style='text-indent:" + spaceNum + "'>" + contentH + "</a><br/>");//在目标DIV中添加内容
            }
        });

        // 当页面向下滑动 500px 出现"返回顶部" 按钮
        $(window).scroll(function () {
            if ($(window).scrollTop() > 500) {
                $('#backToTop').css('display', 'block');
            } else {
                $('#backToTop').css('display', 'none');
            }
        });
        // 点击按钮，返回页面顶部
        $("#backToTop").on("click", function () {
            $("html").animate({
                scrollTop: 0
            }, 300)
        })
    });
});

